package com.pirestupppai.adapter;

import android.content.Context;
import android.text.SpannableString;
import android.view.View;
import android.widget.TextView;

import com.pirestupppai.R;
import com.pirestupppai.base.BaseAdapter;
import com.pirestupppai.base.BaseViewHolder;
import com.pirestupppai.bean.Comment;
import com.pirestupppai.utils.FaceConversionUtil;
import com.pirestupppai.utils.ImageLoadUtil;
import com.pirestupppai.widgets.view.AvatarView;

import java.util.List;

/**
 * @author: xiaoluo
 * @date: 2017-03-14 10:36
 */
public class CommentListAdapter extends BaseAdapter<Comment> {
    private Context mContext;
    private List<Comment> mList;

    public CommentListAdapter(Context context, List<Comment> list) {
        super(list);
        this.mContext = context;
        this.mList = list;
    }


    @Override
    public int getLayoutId() {
        return R.layout.item_comment_list;
    }

    @Override
    protected void bindData(BaseViewHolder holder, int position) {
        AvatarView mAvatarIv = holder.getView(R.id.comment_avatar);
        TextView mNameTv = holder.getView(R.id.item_comment_list_name_tv);
        TextView mTimeTv = holder.getView(R.id.comment_time);
        TextView mCommentTv = holder.getView(R.id.item_comment_list_comment_tv);
        TextView mReNameTv = holder.getView(R.id.item_comment_list_rename_tv);
        TextView mReTv = holder.getView(R.id.item_comment_list_re_tv);

        Comment comment = mList.get(position);
        ImageLoadUtil.getInstance().loadAvatar(comment.getUser().getAvatar(), mAvatarIv);
        mNameTv.setText(comment.getUser().getNickname());
        mAvatarIv.setUid(comment.getUser().getId(), false);
        mTimeTv.setText(comment.getTpTime());

        // 将emoji表情转化为icon显示 TODO
        SpannableString spannableString = FaceConversionUtil.getInstace()
                .getExpressionString(mContext,
                        String.valueOf(comment.getContent()));
        mCommentTv.setText(spannableString);

        // at用户
        if (comment.getParent_comment() != null) {
            mReTv.setVisibility(View.VISIBLE);
            mReNameTv.setVisibility(View.VISIBLE);
            mReNameTv.setText(comment.getParent_comment().getUser().getNickname());
        } else {
            mReTv.setVisibility(View.GONE);
            mReNameTv.setVisibility(View.GONE);
        }
    }
}
